package com.lock.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lock.entiy.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    // 自定义扣减余额方法（带乐观锁条件）
    @Update("UPDATE user SET balance = balance - #{amount} WHERE id = #{id} AND balance >= #{amount}")
    int decreaseBalance(@Param("id") Long id, @Param("amount") BigDecimal amount);
}
